import hmac
from libnum import n2s,s2n
import hashlib
from Crypto.Cipher import DES
dhp=s2n('\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xC9\x0F\xDA\xA2\x21\x68\xC2\x34\xC4\xC6\x62\x8B\x80\xDC\x1C\xD1\x29\x02\x4E\x08\x8A\x67\xCC\x74\x02\x0B\xBE\xA6\x3B\x13\x9B\x22\x51\x4A\x08\x79\x8E\x34\x04\xDD\xEF\x95\x19\xB3\xCD\x3A\x43\x1B\x30\x2B\x0A\x6D\xF2\x5F\x14\x37\x4F\xE1\x35\x6D\x6D\x51\xC2\x45\xE4\x85\xB5\x76\x62\x5E\x7E\xC6\xF4\x4C\x42\xE9\xA6\x37\xED\x6B\x0B\xFF\x5C\xB6\xF4\x06\xB7\xED\xEE\x38\x6B\xFB\x5A\x89\x9F\xA5\xAE\x9F\x24\x11\x7C\x4B\x1F\xE6\x49\x28\x66\x51\xEC\xE6\x53\x81\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF')
dhg=2
dhpi=s2n('\xDB\x58\x40\xCD\x93\x72\x8B\x76\xD1\x71\xE0\xD7\x63\xBC\x78\x94\xF9\xAC\xA4\x1E\xD0\x2C\x07\xFB\x2B\x10\xEC\x6F\xF9\x43\x43\xBC\x65\x81\x36\x62\x79\x0A\x1B\x51\x88\x13\xD4\x97\x42\x35\x73\xFF\xC7\x70\xDA\xC8\xEF\x18\x34\x4D\x99\x53\x2E\x0A\x5D\x1E\xF4\x43\x04\x9C\xB0\x6B\xA8\x69\x9D\x49\x04\xF4\xD4\x70\xD1\xB9\x2E\x2B\x0D\x86\x21\x2D\x89\xFF\x8E\xDE\x90\x01\xD5\x69\x7F\x6C\xB4\x2E\x71\x5D\x0C\x49\x07\xBE\x6B\x62\x28\x0B\xEE\x8F\xDD\xAE\x60\x48\xCE\x47\x9A\xED\x9B\x0F\xF0\x3B\xAA\x54\x93\x5D\xC1\x28\xF7\x5D')
dhpr=s2n('\x7C\xFA\x40\x2B\x3F\xD6\x7B\xF1\xF4\xDE\x20\x4A\x6B\x8A\xF8\x44\x14\x4F\x1F\x8C\x27\x5F\x5A\x93\xD8\xA6\xCA\xDF\xB2\x95\xA4\xE8\x20\xE2\x5C\x3D\x18\x48\x76\xAF\xC5\x31\x04\x67\x4C\x73\xC3\xFF\x26\xA2\x9C\x09\xC9\xB5\x5F\xB4\xD8\x98\x49\xA2\x37\x62\xE3\x2A\xA0\xCF\x83\x88\x4A\x1C\x06\x97\x5A\x35\x5B\xF6\xAA\x98\x79\x0D\xEB\xC2\xBF\xFB\x83\x41\x15\x02\x79\xEB\xC1\x2C\xBF\xB9\xF6\x77\xB0\xE5\xFF\x34\x97\x82\x51\xCB\xF7\x8E\x45\x14\xCE\xB5\x3F\xAF\xB0\x14\x85\x43\x50\x8A\xB6\x45\x95\x15\x2A\xA3\x2A\xA0\xAD\x3A')
rnda=217227749115035578303115991742495457394555440946835514581165277149237157052227668403784536767326288414650333354135580192264021152700162919686294299135414279647180805138410303
rndb=162938785206550875564738389732121139210582420609551964823025935645144235158388990738283910163537245485378422827807450374238085561899166174523954514183122557647647478238328309
dh=pow(dhpi,rndb,dhp)
dh1=pow(dhpr,rnda,dhp)
assert dh==dh1
dh=n2s(dh)
Ni_b='\x97\x00\x3e\x96\xbc\x24\xfc\xf4\x33\x01\xd1\xc4\x3c\x8f\x39\xdb'
Nr_b='\x91\xf6\x7d\x69\x87\xaf\x88\x55\xe0\x0f\x7d\xc7\x7c\x1f\x7a\x54'
key='L2Lkey'
c='\x73\x3D\x05\xC9\x29\xE8\x90\x87\x18\x64\x2E\xEE\xBE\x68\xA3\xC7\x10\xC1\x2C\x09\xB2\x2A\x5C\xFB\x14\xED\xD9\x05\x71\xC3\xDB\x7B\x1B\x59\x8E\xF4\x78\xA2\x34\x4E\x44\x92\x50\x79\x20\xF9\x07\x02'
CKYI='\x9a\x4f\x20\xcd\xb1\x31\x48\xb8'
CKYR='\x31\x32\x33\x36\x35\x34\x33\x32'
#dh=137247906241040090919876955385584427953146893027590677633961074744220353577993931739850208608460762088573995334151351475802221588909889893766807776125874588605505199531437797262808324394122286799024347058396174077697126829526904781090123860153287092978076421343799399389218986715724110092376523175888317759494
skeyid = hmac.new(key, Ni_b+Nr_b).digest()
skeyid_d = hmac.new(skeyid, dh+CKYI + CKYR + '\x00').digest()
skeyid_a = hmac.new(skeyid, skeyid_d + dh + CKYI + CKYR + '\x01').digest()
skeyid_e = hmac.new(skeyid, skeyid_a + dh + CKYI + CKYR + '\x02').digest()
deskey=skeyid_e[:8]
iv=hashlib.md5(n2s(dhpi)+n2s(dhpr)).digest()[:8]
cipher = DES.new(deskey, DES.MODE_CBC, iv)
print cipher.decrypt(c)

